<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8" />
<title>找回密码-{eyou:global name='web_name' /}</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<link href="{eyou:global name='web_cmspath' /}/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    {eyou:static file="users/skin/css/basic.css" /}
    {eyou:static file="users/skin/css/eyoucms.css" /}
    {eyou:include file="users/skin/css/diy_css.htm" /}
    
    {eyou:static file="/public/static/common/js/jquery.min.js"/}
    {eyou:static file="/public/plugins/layer-v3.1.0/layer.js"/}
    {eyou:static file="users/skin/js/global.js" /}
</head>

<body class="reg retrieve">


<div class="register_index ey-member">
    <div class="container">
    <form name='theForm' id="theForm" class="form-register panel-body fv-form">
        <div class="mip-reg-logo"><a href="{eyou:global name='web_cmsurl' /}" class="ey-logo"><img src="{eyou:global name='web_logo'/}" /></a></div>
        <div class="mip-reg-heading"><a class="nav-item " href="javascript:void(0)" style="cursor: unset;">找回密码</a></div>
        <div class="form-group group_z">
            <div class="input-group">
                <input type="text" name="mobile" id="mobile" class="form-control" placeholder="手机号码" maxlength="11"/>
            </div>
        </div>

        <div class="form-group group_z">
            <div class="input-group btn-direction">
                <div class="formText">
                    <input type="text" class="form-control" id="mobile_code" name="mobile_code" placeholder="手机验证码" />
                </div>
                <input type="button" id="mobile_button" onclick="get_mobile_code();" class="btn btn-primary sento" value="获取验证码" />
            </div>
        </div>

        {eyou:eq name="$is_vertify" value="1"}
        <div class="form-group group_z">
            <div class="input-group input-group-icon">
                <div class="formText">
                    <input type="text" name="vertify" id="vertify" autocomplete="off" class="form-control" placeholder="图片验证码" />
                    <img src="{eyou:url link='api/Ajax/vertify' vars='type=users_retrieve_password' /}" class="chicuele" id="imgVerifys" onClick="fleshVerify();">
                </div>
            </div>
        </div>
        {/eyou:eq}

        <button id="submitButton" class="btn btn-lg btn-primary btn-block group_z h60 disabled-button" style="width: 100%;" onclick="check_submit();" type="button" disabled="disabled">下一步</button>
        <div class="login-link clearfix"><a class="fr tr" href="{eyou:url link='user/Users/login' /}">返回登录</a></div>
    </form>
    </div>
</div>

<script type="text/javascript">
    $(document).keydown(function(event){
        if(event.keyCode ==13) check_submit();
    });
    
    function fleshVerify(){
        var src = "{eyou:url link='api/Ajax/vertify' vars='type=users_retrieve_password' /}";
        if (src.indexOf('?') > -1) {
            src += '&';
        } else {
            src += '?';
        }
        src += 'r='+ Math.floor(Math.random()*100);
        $('#imgVerifys').attr('src', src);
    }
    var input = document.getElementById('mobile');
    var input = document.getElementById('mobile_code');
    {eyou:eq name="$is_vertify" value="1"}
    var input = document.getElementById('vertify');
    {/eyou:eq}
    
    var submitButton = document.getElementById('submitButton');
    
    input.addEventListener('input', function() {
      if (input.value.length > 0) {
        submitButton.disabled = false;
        submitButton.classList.remove('disabled-button');
        submitButton.classList.add('enabled-button');
      } else {
        submitButton.disabled = true;
        submitButton.classList.remove('enabled-button');
        submitButton.classList.add('disabled-button');
      }
    });

    function check_submit()
    {
        var mobile = $("#mobile").val();
        // 手机号是否为空
        if (!mobile) {
            $("#mobile").focus();
            layer.msg(ey_foreign_users28, {time: 1500});
            return false;
        }
        
        // 手机格式不正确
        var reg = /^1[0-9]{10}$/i;
        if (!reg.test(mobile)) {
            $("#mobile").focus();
            layer.msg('请输入正确的手机号码！', {time: 1500});
            return false;
        }

        var mobile_code = $("#mobile_code").val();
        // 手机验证码是否为空
        if (!mobile_code) {
            $("#mobile_code").focus();
            layer.msg(ey_foreign_users30, {time: 1500});
            return false;
        }

        layer_loading('正在处理');
        $.ajax({
            url: "{eyou:url link='user/Users/retrieve_password_mobile' /}",
            data: $('#theForm').serialize(),
            type:'post',
            dataType:'json',
            success:function(res){
                layer.closeAll();
                if (res.code == 1) {
                    window.location.href = res.url;
                } else {
                    layer.msg(res.msg, {time: 2000, icon: 5});
                }
            },
            error : function(e) {
                layer.closeAll();
                showErrorAlert(e.responseText);
            }
        });
    };

    function get_mobile_code() {
        var mobile = $("#mobile").val();
        // 手机号是否为空
        if (!mobile) {
            $("#mobile").focus();
            layer.msg(ey_foreign_users28, {time: 1500});
            return false;
        }
        
        // 手机格式不正确
        var reg = /^1[0-9]{10}$/i;
        if (!reg.test(mobile)) {
            $("#mobile").focus();
            layer.msg('请输入正确的手机号码！', {time: 1500});
            return false;
        }

        // 设置为不可点击
        $("#mobile_button").val('获取中…').attr('disabled', 'disabled');

        layer_loading('正在处理');
        $.ajax({
            url: '{$RootDir}/index.php?m=api&c=Ajax&a=SendMobileCode&_ajax=1',
            data: {mobile: mobile, is_mobile: true, source: 4},
            type:'post',
            dataType:'json',
            success:function(res){
                layer.closeAll();
                if (res.code == 1) {
                    countdown();
                    layer.msg(res.msg, {time: 1500});
                } else {
                    $("#mobile_button").val('获取验证码').removeAttr("disabled");
                    showErrorAlert(res.msg);
                }
            },
            error : function(e) {
                layer.closeAll();
                $("#mobile_button").val('获取验证码').removeAttr("disabled");
                showErrorAlert(e.responseText);
            }
        });
    };

    function countdown() {
        // 倒计时
        var setTime;
        var time = 120;
        setTime = setInterval(function() {
            if(0 >= time){
                clearInterval(setTime);
                return;
            }
            time--;
            $("#mobile_button").val(time+'秒').attr('disabled', 'disabled');
            if(time == 0) $("#mobile_button").val('获取验证码').removeAttr("disabled");
        }, 1000);
    };
</script>

</body>
</html>